package ObjectGame;

import java.util.Random;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class ConKien {
	private int xk, yk;
	private int vt=0,tocdo=2;
	private boolean isLive;
	private Image img;
	Random ran;
	private int time=0;
	boolean anbanh=false;
	public ConKien(int x, int y,int tocdo) {
		this.xk = x;
		this.yk = y;
		this.tocdo=tocdo;
		isLive = true;
		ran=new Random();
		img=ImageStatic.antlive;
		
	}
	public void reset()
	{
		isLive=true;
		yk =ran.nextInt(20)-20;
		vt=0;
		img=ImageStatic.antlive;
		time=0;
		anbanh=false;
		
	}
	public void draw(Graphics g) {
		g.drawRegion(img, vt*25, 0,25, 35, 0, xk, yk, Graphics.TOP
				| Graphics.LEFT);
	}

	public void update() {
		if (time==20) {reset();return;}
		if (!isLive) 
		{	time+=1;
			return;
		}
		if (vt==2) vt=0;
		else vt++;
		
		if (yk >380) {
			yk =ran.nextInt(20)-20;
			isLive = true;
			anbanh=true;
		} else {
			yk = yk + tocdo;
		}
	}
  public boolean isAnbanh() {
		return anbanh;
	}
	public void setAnbanh(boolean anbanh) {
		this.anbanh = anbanh;
	}
public boolean kiemtracham(int x,int y)
  {
	 if (x >= xk && x <= xk + 25 && y >= yk && y <= yk + 35)
	 {
		 isLive=false;
		 img=ImageStatic.antdie;
		 return true;
	 }
	 return false;
  }
	public int getX() {
		return xk;
	}

	public void setX(int x) {
		this.xk = x;
	}

	public int getY() {
		return yk;
	}

	public void setY(int y) {
		this.yk = y;
	}

	public int getTocdo() {
		return tocdo;
	}

	public void setTocdo(int tocdo) {
		this.tocdo = tocdo;
	}

	public boolean isLive() {
		return isLive;
	}

	public void setLive(boolean isLive) {
		this.isLive = isLive;
	}
}
